Exercise: Array-Based Lists
Solve a task regarding a more efficient implementation of the addAll() method in array-based lists.
We'll cover the following
Task#
The List method addAll(i,c) inserts all elements of the Collection, c, into the list at position i. (The add(i, x) method is a special case where c = {x}.) It is not efficient to implement addAll(i,c) by repeated calls to add(i,x). Design and implement a more efficient implementation in which there is no repeated calls to the add(i,x) method.
Samle input
The sample input will be as follows:
list: 1 2 3
list2: 4 5 6
Expected output
The expected output will be as follows:
List elements:
1
4
5
6
2
3
Try it yourself first. If you have trouble getting to the solution, you can move to the solution section to see how to solve the problem. We’ll go through the in-depth solution in the next lesson.
Good luck!
Note: You must implement the method
addAll2()in the below code starting at line 42.
Discussion on Array-Based Lists
Solution: Array-Based Lists